package gstudio.views;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

public class PropertyListenerManager {

	private static PropertyListenerManager gsPropertyInvoke;

	private List<IViewToSave> viewSaveActionList;

	public static PropertyListenerManager getInstance() {
		if (gsPropertyInvoke == null)
			gsPropertyInvoke = new PropertyListenerManager();
		return gsPropertyInvoke;
	}

	private ArrayList<IPropertyChangeListener> propertyListeners = new ArrayList<IPropertyChangeListener>();

	private PropertyListenerManager() {
		viewSaveActionList = new ArrayList<IViewToSave>();
	}

	public void registerSaveAction(IViewToSave view) {
		viewSaveActionList.add(view);
	}

	public void doViewsSave() {
		for (IViewToSave a : viewSaveActionList) {
			a.viewDoSave();
		}
	}
	 
	// A public method that allows listener registration
	public void register(IPropertyChangeListener listener) {
		if (!propertyListeners.contains(listener))
			propertyListeners.add(listener);
	}

	// A public method that allows listener registration
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
		propertyListeners.remove(listener);
	}

	public void sendChangeMeassage(String propertyType, Object obj) {
		for (IPropertyChangeListener view : propertyListeners) { 
			view.propertyChange(new PropertyChangeEvent(this, propertyType,
					null, obj));
		}
	}

}